<template>
  <view class="box">
    <view class="tou top" :style="'padding-top:' + statusBarHeight1 + 'px'"> </view>
    <view class="tou top fixed" :style="'padding-top:' + statusBarHeight1 + 'px'">
      <image
        class="image1"
        @click="fanhui"
        src="https://pic.bangbangtongcheng.com/static/fanhui_bai.png"
      />
      <text class="image1-txt">
        {{ title }}
      </text>
      <!-- <view class="merchantMana-select" :class="status?'':'forbid'">
				<uni-data-select v-model="merchantValue" placeholder="管理" @change="change22" :clear="false"
					:noChange='true' :localdata="merchantOptions"></uni-data-select>
			</view> -->
    </view>
    <view class="v2-merchant-mana-main">
      <view class="merchant-info" v-if="merchantValue == ''">
        <view class="tips" v-if="prePageParam.statusDesc && prePageParam.statusDesc != '正常'">{{
          prePageParam.statusDesc == '经营异常' ? '该商家近7日无操作' : prePageParam.statusDesc
        }}</view>
        <view class="flex_end">
          <view class="address">地址：{{ prePageParam.storeAddress }}</view>
          <image
            class="img"
            @click="openMap(prePageParam)"
            src="https://pic.bangbangtongcheng.com/static/fei.png"
          />
        </view>
      </view>
      <view class="merchant1-list">
        <block v-for="(item, index) in Recommend" :key="index">
          <view class="merchant1-item" :key="item.id" v-if="index == 0">
            <view class="merchant1-item-left">
              <image
                src="https://pic.bangbangtongcheng.com/static/member/android.png"
                mode="aspectFill"
                class="merchant1-item-img"
              ></image>
              <template v-if="4 == merchantValue || 5 == merchantValue">
                <view class="merchant1-item-left-mask" @click="goScan">
                  <image
                    src="https://pic.bangbangtongcheng.com/static/saoma_1.png"
                    mode="aspectFill"
                    class=""
                    style="width: 56rpx; height: 56rpx"
                  ></image>
                </view>
              </template>
            </view>
            <view class="merchant1-item-right">
              <view class="merchant1-title">
                <text>二维码</text>
                <view class="merchant1-title-right">
                  <template v-if="4 == merchantValue">分配: {{ qrCodeList.length }} 张</template>
                  <template v-if="5 == merchantValue">收回: {{ qrCodeList.length }} 张</template>
                </view>
              </view>
              <view class="merchant1-info" style="white-space: nowrap">
                <view class="merchany-info-box line1"> 已绑定：{{ item.bound || 0 }} </view>
                <view class="merchany-info-box" style="width: auto">
                  未绑定：{{ item.unbound || 0 }}
                </view>
              </view>
            </view>
          </view>
          <view class="merchant1-item" :key="index" v-else>
            <view class="merchant1-item-left">
              <image :src="item.giftPicture" mode="aspectFill" class="merchant1-item-img"></image>
            </view>
            <view class="merchant1-item-right">
              <view class="merchant1-title">
                <view
                  class="merchant1-title-name"
                  :class="item.inventoryAlertValue >= item.stock ? 'red' : ''"
                >
                  <view class="merchant1-title-name-text">{{ item.giftName }}</view>
                  <view v-if="item.month === 2" class="red-type"> (已过期) </view>
                  <view v-else-if="item.month === 3" class="red-type"> (未生效) </view>
                </view>

                <view class="merchant1-title-right">
                  <template v-if="4 == merchantValue"
                    >送货：
                    <view class="merchant1-title-right-input">
                      <u-number-box
                        @change="inputChange"
                        :showMinus="false"
                        :inputWidth="40"
                        color="#64B6A8"
                        buttonSize="21"
                        bgColor="transparent"
                        :showPlus="false"
                        :min="0"
                        maxlength="4"
                        integer
                        v-model="item.number"
                      ></u-number-box>
                    </view>

                    份
                  </template>
                  <template v-if="5 == merchantValue">
                    取货：
                    <view class="merchant1-title-right-input">
                      <u-number-box
                        @change="inputChange"
                        :showMinus="false"
                        :inputWidth="40"
                        color="#64B6A8"
                        buttonSize="21"
                        bgColor="transparent"
                        :showPlus="false"
                        :min="0"
                        maxlength="4"
                        integer
                        v-model="item.number"
                      ></u-number-box>
                    </view>
                    份
                  </template>
                </view>
              </view>
              <!-- 	<view class="" style="color:#E00000;font-size: 24rpx;"
								v-if="4==merchantValue&&item.month==3">
								未生效
							</view>
							<view class="" style="color:#E00000;font-size: 24rpx;"
								v-if="5==merchantValue&&item.month==2">
								已过期
							</view> -->
              <view class="merchant1-info" style="white-space: nowrap">
                <view
                  class="merchany-info-box line1"
                  v-if="merchantValue == 5 || merchantValue == 4"
                >
                  上月送出：{{ item.sendNumber || 0 }}
                </view>
                <view class="merchany-info-box line1" v-else>
                  当月送出：{{ item.sendNumber || 0 }}
                </view>

                <view
                  class="merchany-info-box"
                  :class="item.inventoryAlertValue >= item.stock ? 'red' : ''"
                >
                  库存：{{ item.stock || 0 }}
                </view>
              </view>
            </view>
          </view>
        </block>
      </view>
      <view v-if="Recommend.length == 0 && mode == 'default'" class="none">
        <image src="https://pic.bangbangtongcheng.com/static/none.png" mode="widthFix" />
        <view>{{ downStatus ? '加载中...' : '没有更多数据了' }}</view>
      </view>
      <view class="img_box" v-if="merchantValue == 5 || merchantValue == 4">
        <view class="title"> <text class="red">*</text>上传出入库凭证 </view>
        <view class="img_item_box">
          <view class="item" v-for="(item, index) in voucherList" :key="index">
            <image :src="item.url" mode="scaleToFill" />
            <view class="maskimg" v-show="item.isShow"></view>
            <cCircle
              class="cCircle"
              v-show="item.isShow"
              :class="item.progress == 100 ? 'hide1' : ''"
              :circleWidth="4"
              :size="60"
              :percent="Number(item.progress)"
            ></cCircle>
            <view class="close" @click="closeVoucher(index)">
              <text class="cuIcon-close"></text>
            </view>
          </view>
          <view class="item add" @tap="ChooseImage" v-if="voucherList.length < 3">
            <text class="cuIcon-add"></text>
          </view>
        </view>
      </view>
      <view class="down" v-show="Recommend.length != 0 && !downStatus && mode == 'default'"
        >没有更多了</view
      >
      <view class="fill-box-mask"></view>
      <view class="fill-box" v-if="merchantValue == 5 || merchantValue == 4">
        <view class="cu-btn fill-box-cancel" @click.stop="cancel">取消</view>
        <view class="cu-btn fill-box-confirm" @click.stop="submit">
          {{ 4 == merchantValue ? '确认分配' : '确认收回' }}
        </view>
      </view>
      <view class="fill-box" v-if="merchantValue == ''">
        <view class="cu-btn fill-box-confirm fill-box-confirm1" @click="open"> 管理 </view>
      </view>
      <!-- <view v-if="scrollTop>20" class="hui" @click="totop">
				<image src="https://pic.bangbangtongcheng.com/static/top.png" />返回顶部
			</view> -->
    </view>
    <uni-popup ref="binds44" class="popup" type="bottom" :isMaskClick="true">
      <view class="btn_box">
        <view class="button" :class="prePageParam.status == 0 ? 'hide' : ''" @click="change22(1)">
          送货
        </view>
        <view class="button" @click="change22(2)"> 取货 </view>
      </view>
    </uni-popup>
    <view class=""></view>
  </view>
</template>

<script>
  import cCircle from '../components/circle.vue'
  //#ifdef H5
  import wxshare from '../utils/index.js'
  //#endif
  var numToSort = {}
  var count = 100100
  import { mapGetters } from 'vuex'
  export default {
    components: {
      cCircle,
    },
    data() {
      return {
        mode: 'default',
        userInfo: uni.getStorageSync('Pduser'),
        scrollTop: 0,
        Recommend: [],
        downStatus: true,
        upStatus: true,
        trigger: false,
        prePageParam: {},
        param: {
          pageNo: 1,
          pageSize: 99,
        },
        title: '啊啊洗车',
        merchantValue: '',
        merchantOptions: [
          {
            value: '1',
            text: '送货',
          },
          {
            value: '2',
            text: '取货',
          },
        ],
        qrCodeList: [],
        status: false,
        day7: false,
        voucherList: [],
      }
    },
    computed: {
      ...mapGetters(['statusBarHeight1', 'userinfo']),
    },
    async onLoad(opt) {
      this.prePageParam = JSON.parse(decodeURIComponent(opt.res))
      console.log(this.prePageParam)

      this.status = this.prePageParam.status == 1 || this.prePageParam.deleteFlag == 1
      uni.setNavigationBarTitle({
        title: this.prePageParam.merchantName || '',
      })
      this.title = this.prePageParam.merchantName
      await this.getQrCode()
      this.getData()
    },
    onShow() {},
    methods: {
      cancel() {
        // 回到出生状态
        this.merchantValue = ''
        this.submitLoading = false
        this.qrCodeList = []
        this.ids = ''
        this.voucherList = []
        this.Recommend = this.tempRecommend
        this.Recommend.map((item) => {
          item.number = 0
        })
        this.getInitData()
      },
      open() {
        console.log(11111)
        this.$refs.binds44.open()
        console.log(22222)
      },
      submit() {
        // 提交

        // this.qrCodeList = [{
        // 	'codeId': '2KNdvk7j'
        // },{
        // 	'codeId': '36nNvSQV'
        // },{
        // 	'codeId': 'b9YsIbRt'
        // }]
        let uploadStatus = false
        this.voucherList.forEach((el) => {
          if (el.progress != 100) {
            uploadStatus = true
          }
        })
        if (uploadStatus) {
          uni.showToast({
            title: '文件上传中！',
            icon: 'none',
          })
          return
        }
        let imglist = this.voucherList.map((item) => item.url)
        var data = {
          ids: this.qrCodeList.map((item) => item.codeId),
          state: 1,
          adminId: this.userInfo.id,
          merchantsId: this.prePageParam.id,
          voucher: imglist.join(','),
          giftList: this.Recommend.filter((item) => item.number).map((item) => {
            return {
              giftId: item.id,
              number: item.number,
            }
          }),
        }
        // console.log(total,this.Recommend)
        // var total = this.Recommend.filter(item => item.number).reduce((preV, curV) => {
        // 	return {
        // 		number: (+preV.number) + (+curV.number)
        // 	}
        // }, {
        // 	number: 0
        // })
        // console.log(total, this.Recommend)
        // console.log(total)
        // return
        var merchantValue = this.merchantValue
        if (this.merchantValue == 4) {
          //送货
          data.state = 1
          if (!data.ids.length && !this.Recommend.filter((item) => item.number).length) {
            uni.showToast({
              title: '请先选择分配货物',
              icon: 'none',
            })
            return
          }
          if (this.voucherList.length == 0) {
            uni.showToast({
              title: '请上传出入库凭证',
              icon: 'none',
            })
            return
          }
        } else if (this.merchantValue == 5) {
          //取货
          data.state = 2
          if (!data.ids.length && !this.Recommend.filter((item) => item.number).length) {
            uni.showToast({
              title: '请先选择收回货物',
              icon: 'none',
            })
            return
          }
          if (this.voucherList.length == 0) {
            uni.showToast({
              title: '请上传出入库凭证',
              icon: 'none',
            })
            return
          }
          // var erweima = (this.Recommend.filter(item => item.id == 1000000)[0] || {})
          // if (data.ids.length && !(Number(erweima.unbound || 0))) {
          // 	uni.showToast({
          // 		title: '请先发放二维码',
          // 		icon: 'none'
          // 	})
          // 	return
          // }
          if (
            !this.Recommend.filter((item) => item.id != 1000000 && item.number).every(
              (item) => item.stock
            )
          ) {
            uni.showToast({
              title: '请先发放礼品',
              icon: 'none',
            })
            return
          }

          // 1000000
        }
        if (this.submitLoading) {
          return true
        }
        this.submitLoading = true
        uni.showLoading({
          title: '加载中',
          mask: false,
        })
        this.$myRequest
          .post('/api/mobile/vehicleOwner/modifyGiftInventory', data, {
            header: 'application/json',
          })
          .then(
            (res) => {
              console.log(res)
              uni.showToast({
                title: merchantValue == 4 ? '分配成功' : '收回成功',
                icon: 'none',
              })
              // this.getInitData()
              setTimeout(() => {
                this.cancel()
              }, 1000)
              // console.log('11',this.Recommend)
              // this.wxUrl = res.r.gz_url;
              // console.log(this.wxUrl)
            },
            (res) => {
              if (res.code == 500) {
                this.submitLoading = false
                uni.hideLoading()
              }
            }
          )
      },
      inputGood(i, event) {
        console.log(i, event)
      },
      fanhui() {
        uni.navigateBack({
          delta: 1,
        })
      },
      inputChange(e) {
        console.log('e', e)
      },
      openMap(item) {
        // console.log(this.data.latitude, this.data.longitude);
        let that = this
        /* #ifdef H5 */
        let param = window.location.href.split('#')[0]
        uni.request({
          method: 'post',
          data: {
            url: param,
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded',
          },
          url: 'https://www.bangbangtongcheng.com/conven//mob/login/getJsTicket.do',
          success(re) {
            // var longitude = latitude;
            // var latitude = latitude;
            // that.setWxShare(re.data)
            uni.hideLoading()
            wxshare.config({
              debug: false, //是否打开调试
              appId: re.data.appId, // 公众号的唯一标识
              timestamp: re.data.timestamp, // 生成签名的时间戳
              nonceStr: re.data.nonce, // ，生成签名的随机串
              signature: re.data.signature, // 签名
              jsApiList: ['openLocation'],
            })
            wxshare.ready(function () {
              wxshare.openLocation({
                latitude: Number(item.latitude), //目的地latitude
                longitude: Number(item.longitude), //目的地longitude
                name: item.merchantName,
                address: item.storeAddress,
                scale: 15, //地图缩放大小，可根据情况具体调整
              })
            })
          },
        })
        /* #endif */
        /* #ifndef H5 */
        uni.openLocation({
          latitude: Number(item.latitude),
          longitude: Number(item.longitude),
          name: item.storeAddress,
          success: function () {
            console.log('success')
          },
        })
        /* #endif */
      },
      async change22(val) {
        if (val == 1 && this.prePageParam.state == 0) return
        if (+(val || 0) + 3 == 4 && !this.status) {
          return false
        }
        this.merchantValue = +(val || 0) + 3

        if (this.merchantValue != 3) {
          uni.showLoading({
            title: '加载中',
            mask: false,
          })
          this.param.pageNo = 1
          this.Recommend = []
          await this.getData()
        }

        if (this.merchantValue == 4) {
          this.Recommend = this.tempRecommend.filter(
            (item) => item.month == 1 || item.month == 3 || item.id == 1000000
          )
        }
        if (this.merchantValue == 5) {
          this.Recommend = this.tempRecommend.filter(
            (item) => item.month == 1 || item.month == 2 || item.month == 3 || item.id == 1000000
          )
        }
        if (this.merchantValue == 4 || this.merchantValue == 5) {
          this.mode = 'view'

          this.qrCodeList = []
          this.Recommend.map((item) => {
            item.number = 0
          })
        }
        this.$refs.binds44.close()
        console.log('valval', val)
      },

      async getQrCode() {
        return this.$myRequest
          .get('/api/mobile/vehicleOwner/getQrCodeBindInfo', {
            merchantId: this.prePageParam.id,
          })
          .then((res) => {
            this.record = res.record
          })
      },
      ChooseImage() {
        let _this = this
        uni.chooseImage({
          count: 3 - _this.voucherList.length,
          sizeType: ['copressed'],
          // sourceType: ["camera", "album"],
          sourceType: ['camera'],
          success(res) {
            //因为有一张图片， 输出下标[0]， 直接输出地址
            const tempFiles = res.tempFiles
            let panduan = false
            tempFiles.forEach((i, j) => {
              let length = ''
              // #ifdef H5
              length = i.name.length
              let resType = i.name.substring(length - 1, length)
              // #endif
              // #ifndef H5
              length = i.path.length
              let resType = i.path.substring(length - 1, length)
              // #endif
              if (resType != 'g' && resType != 'G') {
                panduan = true
              }
            })
            if (panduan) {
              uni.showToast({
                title: '不支持当前文件格式',
                icon: 'none',
              })
              return
            }
            var imgFiles = res.tempFilePaths
            // console.log(imgFiles);
            if (_this.voucherList.length + imgFiles.length > 3) {
              uni.showToast({
                title: '图片最多不能超过3张',
                duration: 2000,
                icon: 'none',
              })
              return
            }
            let length1 = _this.voucherList.length
            var uper
            imgFiles.forEach((el, index) => {
              let index1 = length1 + index
              _this.voucherList.push({
                url: el,
                progress: 0,
                isShow: true,
              })
              uni.showToast({
                title: '正在上传请稍后',
                icon: 'none',
                duration: 2000,
              })
              uper = uni.uploadFile({
                // 需要上传的地址
                url: 'https://www.bangbangtongcheng.com/conven/ht/attach/qnUpload',
                // filePath  需要上传的文件
                filePath: el,
                name: 'file',
                success(res1) {
                  _this.voucherList[index1].url = JSON.parse(res1.data).data[0].url
                  setTimeout(() => {
                    _this.voucherList[index1].isShow = false
                  }, 2000)
                },
              })
              // onProgressUpdate 上传对象更新的方法
              uper.onProgressUpdate(function (res) {
                // console.log(res);
                _this.voucherList[index1].progress = res.progress
              })
            })
          },
          fail: (fail) => {
            uni.showModal({
              title: '提示',
              content: '操作权限已被拒绝，请手动前往设置',
              confirmText: '立即设置',
              success: (res) => {
                if (res.confirm) {
                  if (plus.os.name === 'iOS') {
                    plus.runtime.openURL('app-settings://')
                  } else {
                    var Intent = plus.android.importClass('android.content.Intent')
                    var Settings = plus.android.importClass('android.provider.Settings')
                    var Uri = plus.android.importClass('android.net.Uri')
                    var mainActivity = plus.android.runtimeMainActivity()
                    var intent = new Intent()
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                    var uri = Uri.fromParts('package', mainActivity.getPackageName(), null)
                    intent.setData(uri)
                    mainActivity.startActivity(intent)
                  }
                }
              },
            })
          },
        })
      },
      goScan() {
        // 去扫码或者直接跳转页面扫码
        let that = this
        uni.$off('commonScanResult')
        uni.$on('commonScanResult', (arr) => {
          var tempArr = [...this.qrCodeList, ...arr]
          var newArr = tempArr.filter((item, index) => {
            return tempArr.map((item) => item.codeId).indexOf(item.codeId) == index
          })
          this.qrCodeList = newArr

          console.log(this.qrCodeList)
        })

        // #ifdef APP-PLUS
        uni.navigateTo({
          url:
            '/pages_my/newScanCoden?from=scanCode&type=' +
            this.merchantValue +
            '&merchantId=' +
            this.prePageParam.id,
        })
        // #endif
        // #ifdef MP-WEIXIN
        uni.navigateTo({
          url:
            '/pages_my/wxScanCode?from=scanCode&type=' +
            this.merchantValue +
            '&merchantId=' +
            this.prePageParam.id,
        })
        // #endif
        // uni.navigateTo({
        // 	url:'/pages_my/newScanCoden?from=scanCode'
        // })
        return
        uni.scanCode({
          scanType: ['qrCode', 'datamatrix'],
          success: function (res) {
            if (res.errMsg == 'scanCode:ok') {
              // var str ="https://a.app.qq.com/o/simple.jsp?pkgname=com.cn.conven&codeId=Xy1a4Qrt&merchantId="
              var reg = /([^?=&]+)=([^&]*)/g
              var res2 = {}
              var tempArr = []
              while ((tempArr = reg.exec(res.result))) {
                res2[tempArr[1]] = tempArr[2]
              }
              that.qrCodeList.push(res2)
              that.goScan()
              console.log(res.result)
              // console.log(res2 )
            }
          },
        })
      },
      closeVoucher(index) {
        this.voucherList.splice(index, 1)
      },
      getYearMonth(year, month) {
        if (!year) {
          var dt = new Date()
        } else {
          var dt = new Date(year, month)
        }
        var yy1 = dt.getFullYear()
        var mm1 = dt.getMonth() + 1
        var dd1 = dt.getDate()
        if (mm1 < 10) {
          mm1 = '0' + mm1
        }
        if (dd1 < 10) {
          dd1 = '0' + dd1
        }
        return yy1 + '-' + mm1
      },
      getInitData() {
        uni.showLoading({
          title: '加载中',
          mask: false,
        })
        this.param.pageNo = 1
        this.Recommend = []
        this.getData()
      },

      getData() {
        console.log('当前页码', this.param.pageNo)
        this.upStatus = false
        this.$myRequest.cancel()
        // 调接口
        return this.$myRequest
          .get('/api/mobile/vehicleOwner/getTodayGiftInformation', {
            merchantId: this.prePageParam.id,
            months: this.merchantValue == 3 || !this.merchantValue ? 1 : 2,
            ...this.param,
          })
          .then((res) => {
            console.log('222')
            if (res.giftInformationList.pageList.length < this.param.pageSize) {
              this.downStatus = false
            }
            // 二维码
            if (!this.Recommend.length && res.giftInformationList.pageList.length) {
              this.Recommend = [
                {
                  id: 1000000,
                  ...this.record,
                  sortIndex: {
                    index: -9999,
                  },
                },
              ]
            }

            // console.log(new Date(this.getYearMonth()).getTime()<new Date('2023-09').getTime())
            // receiveStartTime
            // receiveEndTime

            // 分配或收货数量
            res.giftInformationList.pageList.map((item) => {
              var curStamp = new Date(this.getYearMonth()).getTime()
              var startStamp = new Date(item.receiveStartTime.substr(0, 7)).getTime()
              var endStamp = new Date(item.receiveEndTime.substr(0, 7)).getTime()
              item.number = 0
              item.whetherAdvance = curStamp < endStamp
              item.whetherOverdue = curStamp > startStamp
            })
            this.upStatus = true
            this.trigger = false
            var Recommend = [
              {
                id: 1000000,
                ...this.record,
                sortIndex: {
                  index: -9999,
                },
              },
              ...res.giftInformationList.pageList,
            ]

            if (this.merchantValue == 4 || this.merchantValue == 5) {
              var Recommend1 = Recommend.filter((item) => {
                return !item.batch && item.id != 1000000
              }).map((item) => {
                return {
                  ...item,
                  sortIndex: {
                    index:
                      this.merchantValue == 4 && item.month == 3
                        ? 999
                        : this.merchantValue == 5 && item.month == 2
                        ? 999
                        : -1,
                  },
                }
              })
              var tempArr1 = []
              var Recommend2 = Recommend.filter((item) => {
                return item.batch
              })
              numToSort = {}
              Recommend2.map((item, index) => {
                if (this.merchantValue == 4) {
                  if (item.month == 3) {
                    item.sortIndex = {
                      index: 999,
                    }
                  } else {
                    if (numToSort[`batch${item.batch}`]) {
                      numToSort[`batch${item.batch}`].index++
                    } else {
                      numToSort[`batch${item.batch}`] = {
                        index: 1,
                      }
                    }
                    item.sortIndex = numToSort[`batch${item.batch}`]
                  }
                }
                if (this.merchantValue == 5) {
                  if (item.month == 2) {
                    item.sortIndex = {
                      index: 999,
                    }
                  } else {
                    if (numToSort[`batch${item.batch}`]) {
                      numToSort[`batch${item.batch}`] = {
                        index: numToSort[`batch${item.batch}`].index + 1,
                      }
                    } else {
                      numToSort[`batch${item.batch}`] = {
                        index: 1,
                      }
                    }
                    item.sortIndex = numToSort[`batch${item.batch}`]
                  }
                }
                console.log(`batch${item.batch}`, item)
                tempArr1.push(item)
              })

              Recommend = [
                {
                  id: 1000000,
                  ...this.record,
                  sortIndex: {
                    index: -9999,
                  },
                },
                ...Recommend1,
                ...tempArr1,
              ]
                .map((item) => {
                  if (this.merchantValue == 5) {
                    item.hidden = item.month == 3 && !item.stock
                  }
                  return item
                })
                .filter((item) => !item.hidden)
              Recommend.sort(function (a, b) {
                return a.sortIndex.index - b.sortIndex.index
              })
            } else {
              var Recommend1 = Recommend.filter((item) => {
                return item.id == 1000000
              })
              // Recommend.filter(item => {
              // 	return !item.batch && item.id != 1000000
              // }).map(item => {

              // 	return {
              // 		...item,
              // 		sortIndex: {
              // 			index: -1
              // 		},
              // 	}

              // })
              var tempArr1 = []
              var Recommend2 = Recommend.filter((item) => {
                return item.id != 1000000
              })
              numToSort = {}
              Recommend2.map((item, index) => {
                if (this.merchantValue == 3 || !this.merchantValue) {
                  if (item.month == 3) {
                    item.sortIndex = {
                      index: 999,
                    }
                  } else if (item.month == 2) {
                    item.sortIndex = {
                      index: -2,
                    }
                  } else if (!item.batch) {
                    item.sortIndex = {
                      index: -1,
                    }
                  } else {
                    if (numToSort[`batch${item.batch}`]) {
                      numToSort[`batch${item.batch}`].index++
                    } else {
                      numToSort[`batch${item.batch}`] = {
                        index: 1,
                      }
                    }
                    item.sortIndex = numToSort[`batch${item.batch}`]
                  }
                }
                tempArr1.push(item)
              })

              //显示二维码 生效和未生效的数据 2时过期3是未生效
              Recommend = [...Recommend1, ...tempArr1].filter(
                (item) => item.month == 1 || item.id == 1000000
              )
              Recommend.sort(function (a, b) {
                return a.sortIndex.index - b.sortIndex.index
              })
            }
            console.log(Recommend)
            this.Recommend = Recommend
            this.tempRecommend = Recommend
            this.submitLoading = false
            uni.stopPullDownRefresh()
            uni.hideLoading()
            // console.log('11',this.Recommend)
            // this.wxUrl = res.r.gz_url;
            // console.log(this.wxUrl)
          })
        // if (!this.Recommend.length) {
        // 	this.downStatus = false;
        // }
        // this.upStatus = true;
        // this.trigger = false;
        // this.Recommend = this.Recommend.concat(res.recruitmentHomepageRecommendation.pageList);
        // console.log(this.Recommend, "数据")
        // uni.stopPullDownRefresh();
      },
      multipleForOneText(num) {
        switch (num) {
          case 1:
            return '一'
            break
          case 2:
            return '二'
            break
          case 3:
            return '三'
            break
          case 4:
            return '四'
            break
          case 5:
            return '五'
            break
          case 6:
            return '六'
            break
          case 7:
            return '七'
            break
          case 8:
            return '八'
            break
          case 9:
            return '九'
            break
          case 10:
            return '十'
            break
        }
      },
      up() {
        this.Recommend = []
        this.param.pageNo = 1
        this.downStatus = true
        if (this.upStatus) {
          this.trigger = true
          this.getData()
        }
      },
      down() {
        if (this.downStatus) {
          // this.param.pageNo++;
          // this.getData();
        }
      },
      //回到顶部
      totop() {
        uni.pageScrollTo({
          scrollTop: 0,
          duration: 300,
        })
      },
    },
    onPullDownRefresh() {
      this.up()
    },
    onReachBottom() {
      console.log('11', this.downStatus)
      this.down()
    },
    onPageScroll(e) {
      // e.scrollTop
      this.scrollTop = e.scrollTop
    },
  }
</script>

<style lang="scss" scoped>
  .box {
    width: 100%;
    min-height: 100vh;
    // padding-bottom: 130rpx;
    background-color: #fff;
  }

  .fill-box-mask {
    height: 162rpx;
    height: calc(162rpx + constant(safe-area-inset-bottom));
    height: calc(162rpx + env(safe-area-inset-bottom));
  }

  .fill-box {
    position: fixed;
    background-color: #fff;
    left: 0%;
    right: 0%;
    bottom: 0;
    height: 162rpx;
    height: calc(162rpx + constant(safe-area-inset-bottom));
    height: calc(162rpx + env(safe-area-inset-bottom));
    padding-top: 20rpx;
    padding: 20rpx 60rpx 0 60rpx;
    display: flex;
    justify-content: space-between;
    line-height: 80rpx;
    text-align: center;
    font-size: 34rpx;
    font-weight: 400;

    .fill-box-cancel {
      width: 297rpx;
      height: 80rpx;
      background: #ffffff;
      border-radius: 50rpx;
      opacity: 1;
      border: 1rpx solid #64b6a8;
      color: #64b6a8;
    }

    .fill-box-confirm {
      width: 297rpx;
      height: 80rpx;
      background: #64b6a8;
      border-radius: 50rpx;
      opacity: 1;
      color: #ffffff;
    }
    .fill-box-confirm1 {
      width: 100%;
      height: 80rpx;
      background: #64b6a8;
      border-radius: 50rpx;
      opacity: 1;
      color: #ffffff;
    }
  }

  .tou {
    position: relative;
    width: 100%;
    // height: 88rpx;
    text-align: center;
    line-height: 88rpx;
    font-size: 36rpx;
    color: #fff;
    background-color: #64b6a8;
    display: flex;
    align-items: center;
    justify-content: center;

    .image1 {
      position: absolute;
      width: 32rpx;
      height: 32rpx;
      // top: 116rpx;
      left: 30rpx;
    }

    .image1-txt {
      // #ifdef MP-WEIXIN
      position: absolute;
      left: 72rpx;
      // #endif
    }

    .image2 {
      position: absolute;
      width: 56rpx;
      height: 56rpx;
      // top: 104rpx;
      right: 30rpx;
    }

    p {
      position: absolute;
      // top: 90rpx;
      line-height: 45rpx;
      bottom: 21rpx;
      right: 30rpx;
      font-size: 32rpx;
      color: #fff;
    }
  }

  .merchantMana-select {
    position: absolute;

    bottom: 17rpx;
    width: 123rpx;
    height: 48rpx;
    border-radius: 6rpx 6rpx 6rpx 6rpx;
    opacity: 1;
    /* #ifdef H5 || APP */
    // top: 20%;

    right: 30rpx;
    /* #endif */
    /* #ifdef MP-WEIXIN */
    // top: 48%;
    transform: translateX(-50%);
    left: calc(50% + 120rpx);
    // right:200rpx;
    /* #endif */
    // border: 1rpx solid #FFFFFF;
  }

  .v2-merchant-mana-main {
    padding: 30rpx 30rpx 0;
    .merchant-info {
      padding-bottom: 30rpx;
      margin-bottom: 30rpx;
      border-bottom: 1rpx solid #d0d0d0;
      .tips {
        color: #e00000;
        font-size: 30rpx;
        margin-bottom: 28rpx;
        line-height: 34rpx;
      }
      .address {
        width: calc(100% - 50rpx);
      }
      .img {
        margin-left: 10rpx;
        height: 40rpx;
        width: 40rpx;
      }
    }
    .merchant1-list {
      .merchant1-item {
        // height: 132rpx;
        display: flex;
        margin-bottom: 30rpx;

        .merchant1-item-left {
          position: relative;

          .merchant1-item-img {
            width: 132rpx;
            height: 132rpx;
          }

          .merchant1-item-left-mask {
            position: absolute;
            top: 0%;
            left: 0%;
            bottom: 0%;
            right: 0%;
            background-color: rgba(0, 0, 0, 0.7);
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }

        .merchant1-item-right {
          flex: 1;
          margin-left: 20rpx;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          height: 100%;

          .merchant1-title {
            // height: 42rpx;
            font-size: 30rpx;
            font-weight: 400;
            color: #333333;
            line-height: 42rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .merchant1-title-name {
              width: 300rpx;
              .merchant1-title-name-text {
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box; //作为弹性伸缩盒子模型显示。
                -webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
                -webkit-line-clamp: 2; //显示的行
              }
              .red-type {
                color: red;
                font-size: 24rpx;
              }
            }
            .merchant1-title-right {
              color: #64b6a8;
              display: flex;
              align-items: center;

              .merchant1-title-right-input {
                width: 80rpx;
                height: 42rpx;
                border-radius: 4rpx 4rpx 4rpx 4rpx;
                outline: 2rpx solid rgba(100, 182, 168, 0.5);

                font-size: 30rpx;
                font-weight: 400;
                color: #64b6a8;
                line-height: 42rpx;
                text-align: center;
                margin-right: 10rpx;
              }
            }
          }

          .merchant1-info {
            font-size: 24rpx;
            font-weight: 400;
            color: #666666;
            line-height: 34rpx;
            display: flex;
            justify-content: space-between;

            .merchany-info-box {
            }
          }
        }
      }
    }
  }
  .img_box {
    margin-top: 40rpx;
    .title {
      font-size: 30rpx;
      margin-bottom: 20rpx;
      .red {
        color: #e00000;
      }
    }
    .img_item_box {
      display: flex;
      flex-wrap: wrap;
      .item {
        background: #fff;
        margin-right: 35rpx;
        margin-bottom: 35rpx;
        width: 207rpx;
        height: 207rpx;
        border-radius: 8rpx;
        opacity: 1;
        border: 1rpx solid #d8d8d8;
        position: relative;
        overflow: hidden;
        image {
          width: 100%;
          height: 100%;
        }
        .cCircle {
          // background: rgba(0,0,0,0.5);
          width: 120rpx;
          height: 120rpx;
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
        .maskimg {
          background: rgba(0, 0, 0, 0.5);
          width: 100%;
          height: 100%;
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
        .hide1 {
          animation: change 3s;
        }
        @keyframes change {
          0% {
            opacity: 1;
          }
          100% {
            opacity: 0;
          }
        }
        .close {
          width: 48rpx;
          height: 48rpx;
          position: absolute;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 0px 8rpx 0px 8rpx;
          top: 0;
          right: 0;
          color: #fff;
          font-size: 30rpx;
          background: rgba(0, 0, 0, 0.5);
        }
      }
      .item:nth-child(3n) {
        margin-right: 0;
      }
      .add {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 60rpx;
      }
    }
  }
  .box {
    ::v-deep {
      .uni-select {
        line-height: 48rpx;
        height: 48rpx;
        padding: 0;
        text-align: center;

        .uni-select__input-placeholder {
          color: #fff;
          font-size: 26rpx;
          font-weight: 400;
        }

        .uni-select__input-text {
          color: #fff;
        }

        .uni-icons {
          display: none;
        }

        .uni-select__selector {
          padding: 0;
        }

        .uni-popper__arrow {
          left: 52%;
        }

        .uni-select__selector-item {
          color: #5a5e66;
          font-size: 28rpx;
          font-weight: 400;
          line-height: 88rpx;
          margin: 0 10rpx;
          padding: 0;
          justify-content: center;
          border-bottom: 2rpx solid #e0e0e0;

          &:not(:last-child) {
            border-bottom: 2rpx solid #e0e0e0;
          }
        }
      }

      .forbid {
        .uni-select {
          .uni-select__selector-item {
            &:first-child {
              color: #999999;
            }
          }
        }
      }
    }
  }

  .none {
    text-align: center;

    image {
      width: 430rpx;
      margin-bottom: 16rpx;
    }

    view {
      height: 40rpx;
      line-height: 40rpx;
      color: #666;
    }
  }

  .down {
    height: 60rpx;
    line-height: 60rpx;
    // border-top: 2rpx solid #d0d0d0;
    text-align: center;
  }

  .hui {
    position: fixed;
    display: flex;
    align-items: center;
    padding: 10rpx 20rpx;
    right: 30rpx;
    bottom: 154rpx;
    background-color: #fff;
    border-radius: 34rpx;
    font-size: 26rpx;
    box-shadow: 0px 0px 36rpx rgba(0, 0, 0, 0.16);

    image {
      width: 46rpx;
      height: 46rpx;
      margin-right: 18rpx;
    }
  }

  .fixed {
    // display: flex;
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100% !important;
    z-index: 40;
  }
  .hide {
    background: #b6b6b6;
  }
  .btn_box {
    background: #fff !important;
    padding: 40rpx 40rpx 80rpx !important;
    width: 100%;
    border-radius: 40rpx 40rpx 0 0;
  }
  .button {
    width: 100%;
    height: 80rpx;
    border-radius: 49px 49px 49px 49px;
    opacity: 1;
    border: 1rpx solid #999999;
    margin-bottom: 20rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff;
  }
  .red {
    color: red;
  }
</style>
